#include "recordapi.hpp"
///> 事件记录接口，调用底层事件记录接口
using namespace configraion;

const keyvalue::KeyDemoTPDF mKeyDemoEvent[] = KEYDEMO_RECORDEVENT;

static keyvalue *EventKey = 0;

static void RecordEventInit(void)
{
	EventKey = new keyvalue(RECORD_DISK, RECORD_EVENT_ID);
	EventKey->KeyDemo = mKeyDemoEvent;
	EventKey->KeyLen = sizeof(mKeyDemoEvent) / sizeof(keyvalue::KeyDemoTPDF);
	keyvalue::ReocrdInit(EventKey, 3);
	
	EventKey->Open(&mTarget.tFaultRecord[0], 0);
	EventKey->Open(&mTarget.tFaultRecord[1], 1);
	EventKey->Open(&mTarget.tFaultRecord[2], 2);
}

void RecordInit(void)
{
	RecordEventInit();
}

void RecordEvent(FaultRecordTPDF *tEvent)
{
	uint16_t i;
	FaultRecordTPDF tCopy;
	for(i = 0; i < FAULT_RECORD_LEN - 1; i++)
	{
		memcpy((uint8_t *)&tCopy, (uint8_t *)&(mTarget.tFaultRecord[FAULT_RECORD_LEN - 2 - i]),sizeof(FaultRecordTPDF));
		memcpy((uint8_t *)&(mTarget.tFaultRecord[FAULT_RECORD_LEN - 1 - i]), (uint8_t *)&tCopy, sizeof(FaultRecordTPDF));
	}
	memcpy((uint8_t *)&(mTarget.tFaultRecord[0]), (uint8_t *)tEvent, sizeof(FaultRecordTPDF));
	if(EventKey)
	{
		EventKey->Save(tEvent);
	}
}
